#include "TrueText/Config.h"
#include "FtSpans.h"
#include "ftutils.h"

namespace TrueText {

void RasterCallback(const int y, const int count, const FT_Span * const spans, void * const user)
{
  SpansDefinition *sptr = (SpansDefinition *)user;
  for (int i = 0; i < count; ++i) 
	  sptr->spans->push_back(Span(spans[i].x + sptr->shift_x, (sptr->height - y) + sptr->shift_y, spans[i].len, spans[i].coverage));
}

void RenderSpans(FT_Outline * const outline, SpansDefinition *spans)
{
  FT_Raster_Params params;
  memset(&params, 0, sizeof(params));
  params.flags = FT_RASTER_FLAG_AA | FT_RASTER_FLAG_DIRECT;
  params.gray_spans = RasterCallback;
  params.user = spans;

  FT_Outline_Render(GetLibraryHandle(), outline, &params);
}


}